﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using EqRepair.Code.Classes;
using EqRepair.Code.Data;

namespace EqRepair.Web
{
	public partial class MyOrder : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			ButtonOrdFin.Visible = false;
			updateOrd();
		}
		public void updateOrd()
		{
			try
			{
				using (var db = new DataClasses2DataContext())
				{
					int Curuser = new SessionAuthentification(Session).GetCurrentUserID();

					GridViewOrd.DataSource = null;
					PanelOrd.Visible = false;
					//int idR = Int32.Parse(GridView1.SelectedRow.Cells[1].Text);

					PanelOrd.Visible = true;
					GridViewOrd.DataSource = null;
					GridViewOrd.DataSource = from lnk in db.DetachmentRepairs
					                         where (lnk.ResponsibleId == Curuser)
					                         select new
					                                	{
					                                		lnk.Id,
					                                		lnk.RequestId,
					                                		lnk.RequestForRepair.Employee.FullName,
					                                		lnk.Status,
					                                		lnk.Descr,
					                                		Equ = lnk.RequestForRepair.EquipmentInOrganization.Equipment.Name,
					                                		Comp = lnk.RequestForRepair.EquipmentInOrganization.Organization.Name,
					                                		Time = lnk.RequestForRepair.EquipmentInOrganization.Equipment.RepairTime
					                                	};
					GridViewOrd.DataBind();
				}

			}
			catch (Exception ex)
			{
				MessageBox.Show("Произошла непредвиденная ошибка. " + ex.Message, "Внимание.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
			}

		}

		protected void ButtonOrdFin_Click(object sender, EventArgs e)
		{
			if (GridViewOrd.SelectedRow!=null)
				Response.Redirect("Print.aspx?rep=ord&id=" + GridViewOrd.SelectedRow.Cells[1].Text);
		}

		protected void GridViewOrd_SelectedIndexChanged(object sender, EventArgs e)
		{
			ButtonOrdFin.Visible = true;
		}


	}
}

